import loginView from '$v/login'
import {
  loginRequest
} from "$a/login"
export default (req, res, ) => {
  // res.render("登录页面")
  //一级路由
  res.render(loginView({}))

  document.loginForm.loginBtn.onclick = async function (e) {
    e.preventDefault()
    const adminName = document.loginForm.adminName.value
    const password = document.loginForm.passWord.value
    try {
      const loginResult = await loginRequest({
        adminName,
        password
      })
      //成功后跳转
      router.go("/adv/adminList")
      //  把token存储在本地
      localStorage.setItem("user_token", loginResult.data.token)
    } catch (e) {
      alert("登录异常" + e.message)
    }
  }
}